
import java.util.Hashtable;

import lejos.nxt.Button;
import lejos.nxt.ButtonListener;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.SensorPortListener;
import lejos.nxt.TouchSensor;
//import java.util.Hashtable;


public class MyEventListener{
	Hashtable<ButtonType,Integer> list;
	boolean start;
	
	public MyEventListener(){
		
		list=new Hashtable<ButtonType,Integer>();
		start=false;
		
		if(Inputs.ins[0]) 	Button.ENTER.addButtonListener(new ButtonListener() {
			@Override
			public void buttonReleased(Button b) {}
			
			@Override
			public void buttonPressed(Button b) {

					synchronized (list) {
							list.put(ButtonType.ENTER,0);LCD.drawString("ENTER", 0, 0);
					}
								
			}
		});
		if(Inputs.ins[1])	Button.ESCAPE.addButtonListener(new ButtonListener() {
			@Override
			public void buttonReleased(Button b) {	}
			
			@Override
			public void buttonPressed(Button b) {

				synchronized (list) {
							list.put(ButtonType.ESCAPE,0);LCD.drawString("ESCAPE", 0, 0);	
				}
			}
		});
		if(Inputs.ins[2])	Button.LEFT.addButtonListener(new ButtonListener() {
			@Override
			public void buttonReleased(Button b) {}
			
			@Override
			public void buttonPressed(Button b) {
				synchronized (list) {
					list.put(ButtonType.LEFT,0);	LCD.drawString("LEFT", 0, 0);
				}
			}
		});
		if(Inputs.ins[3])	Button.RIGHT.addButtonListener(new ButtonListener() {
			@Override
			public void buttonReleased(Button b) {}
			
			@Override
			public void buttonPressed(Button b) {
				synchronized (list) {
					list.put(ButtonType.RIGHT,0);LCD.drawString("RIGHT", 0, 0);
				}
			}
		});

		
		if(Inputs.ins[5])  {new TouchSensor(SensorPort.S4);
			SensorPort.S4.addSensorPortListener(new SensorPortListener() {

					public void stateChanged(SensorPort aSource, int aOldValue, int aNewValue) {

						if(aOldValue==aNewValue)	return;
						if(!start)	return;
						synchronized (list) {            	
							list.put(ButtonType.TOUCH2,0);  	  	LCD.drawString("TOUCH2", 0, 0);}
						}
        });

								
		}
							
		if(Inputs.ins[4])  {new TouchSensor(SensorPort.S3);
		
			SensorPort.S3.addSensorPortListener(new SensorPortListener() {
	
	            public void stateChanged(SensorPort aSource, int aOldValue, int aNewValue) {  
	            	if(aOldValue==aNewValue)	return;
	            	if(!start)	return;
	            synchronized (list) {            	             	
	            	list.put(ButtonType.TOUCH1,0);   LCD.drawString("TOUCH1", 0, 0);         }
	            }
	        });
		}
	}
	


}






































